﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PraiseSystem.Models;

namespace PraiseSystem.Controllers
{
    public class RankListController : Controller
    {
        private PraiseDBContext db = new PraiseDBContext();
        // GET: RankList
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult RankList()
        {
            db.Praises.Add(new Praise() {
                DeleteFlag = false,
                DoRight = "nothing",
                OwnerID = "P4123123",
                PraiseDate = DateTime.Now,
                Receivers = db.Receivers.Where(r => r.ReceiverID == "P4123123").ToList() });
            db.SaveChanges();
            var receivedInfo = (from r in db.Receivers
                               orderby r.ReceivedPraises.Count descending
                               select r).ToList();
            return View(receivedInfo);
        }
    }
}